<template>
  <LoginHeader>联合登录</LoginHeader>
  <section class="container">
    <nav class="tab">
      <a
        href="javascript:;"
        @click="comName = 'CallbackBind'"
        :class="{active: comName === 'CallbackBind'}"
      >
        <i class="iconfont icon-bind" />
        <span>已有小兔鲜账号，请绑定手机</span>
      </a>
      <a
        href="javascript:;"
        @click="comName = 'CallbackPatch'"
        :class="{active: comName === 'CallbackPatch'}"
      >
        <i class="iconfont icon-edit" />
        <span>没有小兔鲜账号，请完善资料</span>
      </a>
    </nav>
    <div class="tab-content">
      <component :is="comName" :openId="openId"></component>
      <!-- <CallbackBind></CallbackBind>
      <CallbackPatch></CallbackPatch> -->
    </div>
  </section>
  <LoginFooter />
</template>

<script>

import LoginHeader from './components/login-header'
import LoginFooter from './components/login-footer'
import CallbackBind from './components/callback-bind.vue'
import CallbackPatch from './components/callback-patch.vue'
import { ref } from 'vue'
import QC from 'qc'
import { reqUserQQLogin } from '@/api/user'
import { useStore } from 'vuex'
import { useRouter } from 'vue-router'
import { message } from '@/components/Message'
export default {
  name: 'PageCallback',
  components: { LoginHeader, LoginFooter, CallbackBind, CallbackPatch },
  setup () {
    const comName = ref('CallbackBind')
    // 获取一下openId
    const openId = ref('')
    const store = useStore()
    const router = useRouter()
    if (QC.Login.check()) {
      QC.Login.getMe((id) => {
        openId.value = id
        console.log('openId', openId)
        reqUserQQLogin(id).then(res => {
          console.log('res', res)
          // 1. 把当前登录成功返回的用户数据 通过提交mutation 存到vuex里
          store.commit('user/setProfile', res.result)
          // 2. 跳转到首页
          router.push('/')
        }).catch(e => {
          // qq没绑定过,登录失败了
          // message({
          //   type: 'error',
          //   text: '你qq得绑定一下啊'
          // })
          console.log('你得绑定手机了')
        })
      })
    }
    return {
      openId,
      comName
    }
  }
}
</script>

<style scoped lang='less'>
.container {
  padding: 25px 0;
}
.tab {
  background: #fff;
  height: 80px;
  padding-top: 40px;
  font-size: 18px;
  text-align: center;
  a {
    color: #666;
    display: inline-block;
    width: 350px;
    line-height: 40px;
    border-bottom: 2px solid #e4e4e4;
    i {
      font-size: 22px;
      vertical-align: middle;
    }
    span {
      vertical-align: middle;
      margin-left: 4px;
    }
    &.active {
      color: @xtxColor;
      border-color: @xtxColor;
    }
  }
}
.tab-content {
  min-height: 600px;
  background: #fff;
}
</style>
